package com.zerox.uilt;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;


public class stream {
    public static void main(String[] args) {

        //filter过滤集合中不符合条件的元素
        List<String> list = Arrays.asList("aa", "bb", "cc", "dd","dd","gg");
        List<String> b = list.stream().filter(str -> str.contains("b")).collect(Collectors.toList());
        System.out.println(b);

        //distinct去除集合中重复的选项
        List<String> collect = list.stream().distinct().collect(Collectors.toList());
        System.out.println(collect);

//        ---------------------------------------------------------------------------------
        //地址
        List<Person> person = new ArrayList<>();
        person.add(new Person(1,"aa"));
        person.add(new Person(2,"bb"));
        person.add(new Person(3,"cc"));
        person.add(new Person(3,"cc"));
        List<Person> collect1 = person.stream().distinct().collect(Collectors.toList());
        System.out.println(collect1);


//        limit
        List<String> limits = list.stream().limit(2).collect(Collectors.toList());
        System.out.println(limits);

//        skip
        List<String> skip = list.stream().skip(3).collect(Collectors.toList());
        System.out.println(skip);

//        map
        List<String> map1 = list.stream().map(str -> "1" + str +"2").collect(Collectors.toList());
        System.out.println(map1);
    }
}
